<?php
namespace admin\action;

use herosphp\http\HttpRequest;
use herosphp\utils\AjaxResult;
use herosphp\bean\Beans;

/**--tmpl-use--**/

use herosphp\core\Loader;


class FriendLinkCateAction extends CommonAction {

	public function C_start()
	{
		parent::C_start();
	}
	protected $serviceBean="admin.settingFriendlinkCate.service";
	public function add(HttpRequest $request) {
	
		parent::add($request);
		$parent_idoptions = Loader::model('settingFriendlinkCate')->getItems();
		$this->assign('parent_idoptions',$parent_idoptions);
		$this->assign("admin_name",adminName());
		$this->assign("title", "添加分类");
		$this->assign('bread', array('网站设置','分类列表',$this->getTemplateVar('title')));
		$this->assign('breadUrl', array('javascript:;',url('admin/friendLinkCate/index'),'javascript:;'));

	}
	public function edit(HttpRequest $request) {
		$parent_idoptions = Loader::model('settingFriendlinkCate')->getItems();
		$this->assign('parent_idoptions',$parent_idoptions);
		$this->assign("admin_name",adminName());
		parent::edit($request);
		$this->assign("title", "编辑分类");
		$this->assign('bread', array('网站设置','分类列表',$this->getTemplateVar('title')));
		$this->assign('breadUrl', array('javascript:;',url('admin/friendLinkCate/index'),'javascript:;'));
	}
	
	/**-- actionIndex --**/
	public function index(HttpRequest $request) {
		$conditions = array();
		$this->assign('_table','友情链接分类');
		$s_name = $request->getParameter('s_name');
		$this->assign('s_name',$s_name);
		if($s_name !== '' && $s_name!== NULL)$conditions['name'] = '%'.$s_name.'%';
		$s_description = $request->getParameter('s_description');
		$this->assign('s_description',$s_description);
		if($s_description !== '' && $s_description!== NULL)$conditions['description'] = '%'.$s_description.'%';
		$s_addtime = $request->getParameter('s_addtime');
		$this->assign('s_addtime',$s_addtime);
		if($s_addtime !== '' && $s_addtime!== NULL)$conditions['addtime'] = '%'.$s_addtime.'%';
		$s_parent_id = $request->getParameter('s_parent_id');
		$this->assign('s_parent_id',$s_parent_id);
		if($s_parent_id !== '' && $s_parent_id!== NULL)$conditions['parent_id'] = $s_parent_id;
		$s_app_id = $request->getParameter('s_app_id');
		$this->assign('s_app_id',$s_app_id);
		if($s_app_id !== '' && $s_app_id!== NULL)$conditions['app_id'] = '%'.$s_app_id.'%';
		$s_manager_id = $request->getParameter('s_manager_id');
		$this->assign('s_manager_id',$s_manager_id);
		if($s_manager_id !== '' && $s_manager_id!== NULL)$conditions['manager_id'] = $s_manager_id;
		$this->assign('_filter',array('name','description','addtime','setting_friendlink_cate_id','app_id','manager_id'));
		$this->assign('_header',array('分类名称','分类描述','添加时间','父级分类','appid','添加人'));
		$this->setConditions($conditions);
	
		$pagesize = $request->getParameter('pagesize') ? $request->getParameter('pagesize') : $this->getPagesize();
		$order = $request->getParameter('order') ? $request->getParameter('order') : $this->getOrder();
		$order = str_replace('+' , " ",$order);
		$this->setPagesize($pagesize);
		$this->setOrder($order);
		$this->assign('order',$order);
		$this->assign('pagesize',$pagesize);

		$this->page = $request->getParameter('page', 'intval');
		if ( $this->page <=0 ) {
			$this->page = 1;
		}
		$service = Beans::get($this->getServiceBean());
		$total = $service->count($this->getConditions());
		$items = $service->getItems($this->getConditions(), $this->getFields(), $this->getOrder(),
				array($this->getPage(), $this->getPagesize()), $this->getGroup(), $this->getHaving());
		//初始化分页类
		$this->generatePageMenu($total);
		$this->assign('total',$total);
		$this->assign('items',$items);
		$this->setView(strtolower($request->getAction()) . '/index');

		$parent_idoptions = Loader::model('settingFriendlinkCate')->getItems();
		$this->assign('parent_idoptions',$parent_idoptions);
		$this->assign("title", "分类列表");
		$this->assign('bread', array('网站设置',$this->getTemplateVar('title')));
		$this->assign('breadUrl', array('javascript:;','javascript:;'));
	}
	public function do_add(HttpRequest $request)
	{
		$data = $request->getParameter('data');
		$request->addParameter('data',$data);
		parent::do_add($request);	
	}
	public function do_edit(HttpRequest $request){
		$data = $request->getParameter('data');
		$request->addParameter('data',$data);
		parent::do_edit($request);	
	}
	
	

}
